package com.dmzc.stage2.chapter15;

public interface TaskLifecycle<T> {
    /**
     * 任务启动时会触发
     */
    void onStart(Thread thread);
    /**
     * 任务运行时会触发
     */
    void onRunning(Thread thread);
    /**
     * 任务结束运行会触发
     */
    void onFinish(Thread thread,T result);
    /**
     * 任务执行错误会触发
     */
    void onError(Thread thread,Exception e);

    class EmptyLifecycle<T> implements TaskLifecycle<T>{

        /**
         * 任务启动时会触发
         *
         * @param thread
         */
        @Override
        public void onStart(Thread thread) {
            System.out.println("start");
        }

        /**
         * 任务运行时会触发
         *
         * @param thread
         */
        @Override
        public void onRunning(Thread thread) {
            System.out.println("running");
        }

        /**
         * 任务结束运行会触发
         *
         * @param thread
         * @param result
         */
        @Override
        public void onFinish(Thread thread, T result) {
            System.out.println("finish");
        }

        /**
         * 任务执行错误会触发
         *
         * @param thread
         * @param e
         */
        @Override
        public void onError(Thread thread, Exception e) {
            System.out.println("error");
        }
    }

}
